import {
    getOrderDetail
} from '../../api/order.js';
import {
    setFormId
} from '../../api/api.js';
import {
    userShare
} from '../../api/user.js';
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        parameter: {
            'navbar': '1',
            'return': '1',
            'title': '支付成功'
        },
        orderId: '',
        order_pay_info: {
            paid: 1
        },
        hidden: true
    },
    onLoadFun: function() {
        this.getOrderPayInfo();
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        if (!options.order_id) return app.Tips({
            title: '缺少参数无法查看订单支付状态'
        }, {
            tab: 3,
            url: 1
        });
        this.setData({
            orderId: options.order_id,
            status: options.status || 0,
            msg: options.msg || ''
        });
    },
    /**
     * 
     * 支付完成查询支付状态
     * 
     */
    getOrderPayInfo: function() {
        var that = this;
        wx.showLoading({
            title: '正在加载中'
        });
        getOrderDetail(this.data.orderId).then(res => {
            console.log(res)
            wx.hideLoading();
            that.setData({
                order_pay_info: res.data,
                'parameter.title': res.data.paid ? '支付成功' : '支付失败'
            });
        }).catch(err => {
            wx.hideLoading();
        });
    },
    onShareAppMessage: function() {
        var that = this;
        userShare();
        // console.log('/pages/goods_details/index?id=' + that.data.order_pay_info.cartInfo[0].product_id + '&spid=' + that.data.order_pay_info.uid + '&isshare=' + 1 + '&order_id=' + that.data.order_pay_info.id)
        return {
            title: that.data.order_pay_info.cartInfo[0].productInfo.store_name || '',
            imageUrl: that.data.order_pay_info.cartInfo[0].productInfo.image || '',
            path: '/pages/goods_details/index?id=' + that.data.order_pay_info.cartInfo[0].product_id + '&spid=' + that.data.order_pay_info.uid + '&isshare=' + 1 + '&order_id=' + that.data.order_pay_info.id,
        }
    },
    /**
     * 去首页关闭当前所有页面
     */
    goIndex: function(e) {
        var formId = e.detail.formId;
        setFormId(formId);
        wx.switchTab({
            url: '/pages/index/index'
        });
    },

    /**
     * 
     * 去订单详情页面
     */
    goOrderDetails: function(e) {
        var formId = e.detail.formId;
        setFormId(formId);
        wx.navigateTo({
            url: '/pages/order_details/index?order_id=' + this.data.orderId
        });
    },

    goOrderDetailsorder: function(e) {
        // var formId = e.detail.formId;
        // setFormId(formId);
        wx.navigateTo({
            url: '/pages/order_list/index?status=1'
        });
    },
    // 拼购
    Spellbutton: function() {
        var that = this
        that.setData({
            hidden: false
        })
    },
    giveup: function() {
        this.setData({
            hidden: true
        })
    },
    Spell: function() {
        var that = this


    },
})